home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 173 / 173.xpi / chrome / gm-notifier.jar / content / gm-notifier / gm-preferences.xul < prev    next >
Extensible Markup Language  |  2009-09-28  |  15KB  |  365 lines

  1. <?xml version="1.0"?>
  2. <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
  3. <?xml-stylesheet href="chrome://gm-notifier/content/gm-notifier.css" type="text/css"?>
  4.  
  5. <!DOCTYPE dialog SYSTEM "chrome://gm-notifier/locale/gm-notifier.dtd">
  6. <dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  7.         title="¬ifier.prefs.name;"
  8.         buttons="accept, cancel, extra2"
  9.         style="padding:0px; margin:0px;"
  10.         ondialogaccept="wm_prefs_accept()" onload="wm_prefs_load()"
  11.         buttonlabelextra2="¬ifier.prefs.debugconsole.value;">
  12.  
  13.   <script type="application/x-javascript" src="chrome://gm-notifier/content/gm-prefs.js"/>
  14.   <script>
  15.     <![CDATA[
  16.     var wm_prefs;
  17.     var prefarray;
  18.  
  19.     function initPrefs() {
  20.       prefarray = [ { id: "prefs.update.interval", name: wm_prefs.PREF_UPDATE_INTERVAL, type: "int" },
  21.                     { id: "prefs.gmload.location", name: wm_prefs.PREF_LOAD_LOCATION, type: "int" },
  22.                     { id: "prefs.load.reset_counter", name: wm_prefs.PREF_LOAD_RESET_COUNTER, type: "bool" },
  23.                     { id: "prefs.autologin.enabled", name: wm_prefs.PREF_AUTOLOGIN_ENABLED, type: "bool" },
  24.                     { id: "prefs.ui.notification.enabled", name: wm_prefs.PREF_NOTIFICATIONS_ENABLED, type: "bool" },
  25.                     { id: "prefs.ui.soundnotification.textbox", name: wm_prefs.PREF_SOUNDNOTIFICATIONS_URI, type: "char" },
  26.                     { id: "prefs.ui.folderview.enabled", name: wm_prefs.PREF_USE_FOLDERVIEW, type: "bool" },
  27.                     { id: "prefs.counter.type", name: wm_prefs.PREF_COUNTER_SHOW_INBOX, type: "bool" },
  28.                     { id: "prefs.statusbar.enabled", name: wm_prefs.PREF_STATUSBAR_ENABLED, type: "bool" },
  29.                     { id: "prefs.ui.soundnotification.enabled", name: wm_prefs.PREF_SOUNDNOTIFICATIONS_ENABLED, type: "bool" },
  30.                     { id: "prefs.use.unsecure.connection", name: wm_prefs.PREF_UNSECURED_CONNECTION, type: "bool" },
  31.                     { id: "prefs.ui.multiaccount.enabled", name: wm_prefs.PREF_MULTIACCOUNT_ENABLED, type: "bool" },
  32.                     { id: "prefs.ui.notification.repeat", name: wm_prefs.PREF_NOTIFICATIONS_REPEAT, type: "bool" }
  33.                   ];
  34.  
  35.       for (i in prefarray) {
  36.         setPreference(prefarray[i]);
  37.       }
  38.     }
  39.  
  40.     function setPreference(aPref) {
  41.       if (aPref) {
  42.         var elm = document.getElementById(aPref.id);
  43.         var value;
  44.  
  45.         if (aPref.type == "int")
  46.           value = wm_prefs.getIntPref(aPref.name);
  47.         else if (aPref.type == "bool")
  48.           value = wm_prefs.getBoolPref(aPref.name);
  49.         else if (aPref.type == "char")
  50.           value = wm_prefs.getCharPref(aPref.name);
  51.  
  52.         setPreferenceUIValue(elm, value);
  53.       }
  54.     }
  55.  
  56.     function setPreferenceUIValue(aElement, aValue) {
  57.       var localName = aElement.localName;
  58.  
  59.       if (localName == "textbox") {
  60.         aElement.value = aValue;
  61.       } else if (localName == "menulist") {
  62.         aElement.selectedIndex = aValue;
  63.       } else if (localName == "checkbox") {
  64.         aElement.checked = aValue;
  65.       }
  66.     }
  67.  
  68.     // saving
  69.  
  70.     function savePrefs() {
  71.       for (i in prefarray) {
  72.         if (prefarray[i].id == "prefs.update.interval") {
  73.           var interval = document.getElementById("prefs.update.interval").value;
  74.           if (!isNaN(interval) && parseInt(interval) >= 1) {
  75.             savePreference(prefarray[i]);
  76.           }
  77.         } else {
  78.           savePreference(prefarray[i]);
  79.         }
  80.       }
  81.     }
  82.  
  83.     function savePreference(aPref) {
  84.       if (aPref) {
  85.         var elm = document.getElementById(aPref.id);
  86.         var value = getValue(elm);
  87.  
  88.         if (aPref.type == "int")
  89.           wm_prefs.setIntPref(aPref.name, value);
  90.         else if (aPref.type == "bool")
  91.           wm_prefs.setBoolPref(aPref.name, value);
  92.         else if (aPref.type == "char")
  93.           wm_prefs.setCharPref(aPref.name, value);
  94.       }
  95.     }
  96.  
  97.     function getValue(aElement) {
  98.       var localName = aElement.localName;
  99.       var value;
  100.  
  101.       if (localName == "textbox") {
  102.         value = aElement.value;
  103.       } else if (localName == "menulist") {
  104.         value = aElement.selectedIndex;
  105.       } else if (localName == "checkbox") {
  106.         value = aElement.checked;
  107.       }
  108.  
  109.       return value;
  110.     }
  111.  
  112.     function wm_prefs_load(){
  113.       wm_prefs = new gm_prefs();
  114.  
  115.       initPrefs();
  116.  
  117.       toggleShowStatusbar();
  118.  
  119.       if (!supportsMultiMode()) {
  120.         document.getElementById("multiAccountHbox").collapsed = true;
  121.       }
  122.  
  123.       var position = wm_prefs.getIntPref(wm_prefs.PREF_STATUSBAR_POSITION);
  124.       if (position > 0)
  125.         document.getElementById("prefs.statusbar.position").value = position;
  126.  
  127.       toogleSoundNotification();
  128.  
  129.       // hide the system notification item if the alert service and growl is not present
  130.       if (!("@mozilla.org/alerts-service;1" in Components.classes) && !("@growl.info/notifications;1" in Components.classes))
  131.         document.getElementById("prefs.ui.notification.enabled").collapsed = true;
  132.  
  133.       // manage accounts button
  134.       var value = wm_prefs.getBoolPref(wm_prefs.PREF_MULTIACCOUNT_ENABLED);
  135.       document.getElementById("prefs.ui.multiaccount.accounts.button").disabled = !value;
  136.  
  137.       updateManageAccountsButton();
  138.       updateNotificationButton();
  139.  
  140.       // console button
  141.       var button = document.documentElement.getButton("extra2");
  142.       button.addEventListener("command", showDebugConsole, false);
  143.       button.setAttribute("icon", "help");
  144.     }
  145.  
  146.     function toogleSoundNotification() {
  147.       var value = document.getElementById("prefs.ui.soundnotification.enabled").checked;
  148.       document.getElementById("prefs.ui.soundnotification.textbox").disabled = !value;
  149.       document.getElementById("prefs.ui.soundnotification.select").disabled = !value;
  150.       updatePreviewButton();
  151.     }
  152.  
  153.     function wm_prefs_accept(){
  154.       savePrefs();
  155.  
  156.       var position = document.getElementById("prefs.statusbar.position").value;
  157.       if (isNaN(parseInt(position)) || position.value < 1) {
  158.         position = 0;
  159.       }
  160.  
  161.       wm_prefs.setIntPref(wm_prefs.PREF_STATUSBAR_POSITION, position);
  162.     }
  163.  
  164.     function selectSound() {
  165.       var nsIFilePicker = Components.interfaces.nsIFilePicker;
  166.       var filepicker = Components.classes["@mozilla.org/filepicker;1"]
  167.                                  .createInstance(nsIFilePicker);
  168.  
  169.       // get dialog title from bundle
  170.       var strbundle = document.getElementById("stringbundle");
  171.  
  172.       filepicker.init(window, strbundle.getString("ChooseSoundDialogTitle"), nsIFilePicker.modeOpen);
  173.       filepicker.appendFilters(nsIFilePicker.filterAll);
  174.       var ret = filepicker.show();
  175.       if (ret == nsIFilePicker.returnOK) {
  176.         document.getElementById("prefs.ui.soundnotification.textbox").value = filepicker.file.path;
  177.       }
  178.  
  179.       updatePreviewButton();
  180.     }
  181.  
  182.     function updatePreviewButton() {
  183.       if ((document.getElementById("prefs.ui.soundnotification.enabled").checked) && (document.getElementById("prefs.ui.soundnotification.textbox").value != ""))
  184.         document.getElementById("prefs.ui.soundnotification.preview").disabled = false;
  185.       else
  186.         document.getElementById("prefs.ui.soundnotification.preview").disabled = true;
  187.     }
  188.  
  189.     function previewSound() {
  190.       var soundUrl = document.getElementById("prefs.ui.soundnotification.textbox").value;
  191.  
  192.       try {
  193.         var sound = Components.classes["@mozilla.org/sound;1"]
  194.                               .createInstance(Components.interfaces.nsISound);
  195.         sound.init();
  196.  
  197.         var shortname = soundUrl.substr(0, 7);
  198.  
  199.         if (shortname == "http://" || shortname == "https:/") {
  200.           var url = Components.classes["@mozilla.org/network/standard-url;1"]
  201.                               .createInstance(Components.interfaces.nsIURL);
  202.           url.spec = soundUrl;
  203.           sound.play(url);
  204.         } else {
  205.           var localFile = Components.classes["@mozilla.org/file/local;1"]
  206.                              .createInstance(Components.interfaces.nsILocalFile);
  207.           localFile.initWithPath(soundUrl);
  208.  
  209.           var ios = Components.classes["@mozilla.org/network/io-service;1"]
  210.                               .getService(Components.interfaces.nsIIOService);
  211.           sound.play(ios.newFileURI(localFile));
  212.         }
  213.       } catch (e) {
  214.         // XXX should alert a message?
  215.         alert(e);
  216.       }
  217.    }
  218.  
  219.     function toggleShowStatusbar() {
  220.       var value = document.getElementById("prefs.statusbar.enabled").checked;
  221.       document.getElementById("prefs.statusbar.position").disabled = !value;
  222.     }
  223.  
  224.     function updateManageAccountsButton() {
  225.       var value = document.getElementById("prefs.ui.multiaccount.enabled").checked;
  226.       document.getElementById("prefs.ui.multiaccount.accounts.button").disabled = !value;
  227.     }
  228.  
  229.     function manageAccounts() {
  230.       window.openDialog("chrome://gm-notifier/content/gm-accounts.xul", "gm-notifier:accounts", "centerscreen,chrome,resizable=no,dependent=yes");
  231.     }
  232.  
  233.     function showDebugConsole() {
  234.       window.openDialog('chrome://gm-notifier/content/console.xul', '_blank', 'chrome,resizable=no,dependent=yes')
  235.     }
  236.  
  237.     function supportsMultiMode() {
  238.       var supports = false;
  239.  
  240.       try {
  241.         var appInfo = Components.classes["@mozilla.org/xre/app-info;1"]
  242.                                 .getService(Components.interfaces.nsIXULAppInfo);
  243.  
  244.         if (appInfo.platformVersion >= "1.8.1")
  245.           supports = true;
  246.       } catch (e) {}
  247.  
  248.       return supports;
  249.     }
  250.  
  251.     function updateNotificationButton() {
  252.       var checked = document.getElementById("prefs.ui.notification.enabled").checked;
  253.  
  254.       document.getElementById("prefs.ui.notification.repeat").disabled = !checked;
  255.     }
  256.  
  257.     ]]>
  258.   </script>
  259.  
  260.   <stringbundle id="stringbundle" src="chrome://gm-notifier/locale/gm-notifier.properties"/>
  261.  
  262.   <description value="¬ifier.prefs.name;" class="notifier-dialog-title"
  263.                style="min-width:400px;"/>
  264.  
  265.   <groupbox>
  266.     <caption label="¬ifier.prefs.groupbox.ui;"/>
  267.     <hbox>
  268.       <checkbox id="prefs.statusbar.enabled"
  269.                 label="¬ifier.prefs.statusbar.show.label;" 
  270.                 accesskey="¬ifier.prefs.statusbar.show.accesskey;"
  271.                 oncommand="toggleShowStatusbar()"/>
  272.       <spacer flex="1"/>
  273.     </hbox>
  274.  
  275.     <hbox class="indent" align="center">
  276.       <label value="¬ifier.prefs.statusbar.position.label;"
  277.              accesskey="¬ifier.prefs.statusbar.position.accesskey;"
  278.              control="prefs.statusbar.position"/>
  279.       <textbox id="prefs.statusbar.position" style="width:2em;" maxlength="2"
  280.                value=""/>
  281.     </hbox>
  282.  
  283.     <label style="margin-top:5px;" value="¬ifier.prefs.logged_in.label;"/>
  284.  
  285.     <vbox class="indent">
  286.       <hbox align="center">
  287.         <label value="¬ifier.prefs.load.location;" control="prefs.gmload.location"
  288.                accesskey="¬ifier.prefs.load.location.accesskey;"/>
  289.         <menulist id="prefs.gmload.location">
  290.           <menupopup>
  291.             <menuitem value="0" label="¬ifier.prefs.load.location.current_tab;"/>
  292.             <menuitem value="1" label="¬ifier.prefs.load.location.new_tab;"/>
  293.             <menuitem value="2" label="¬ifier.prefs.load.location.new_window;"/>
  294.             <menuitem value="3" label="¬ifier.prefs.load.location.new_unfocused_tab;"/>
  295.           </menupopup>
  296.         </menulist>
  297.       </hbox>
  298.  
  299.       <checkbox id="prefs.ui.folderview.enabled" label="¬ifier.prefs.load.folderUI.label;"
  300.                 accesskey="¬ifier.prefs.load.folderUI.accesskey;"/>
  301.  
  302.       <checkbox id="prefs.load.reset_counter"
  303.                 label="¬ifier.prefs.load.reset_counter.label;"
  304.                 accesskey="¬ifier.prefs.load.reset_counter.accesskey;"/>
  305.  
  306.        <checkbox id="prefs.counter.type"
  307.                  label="¬ifier.prefs.counter.type.label;"
  308.                  accesskey="¬ifier.prefs.counter.type.accesskey;"/>
  309.     </vbox>
  310.  
  311.     <hbox id="multiAccountHbox">
  312.       <checkbox id="prefs.ui.multiaccount.enabled"
  313.                 label="¬ifier.prefs.ui.multiaccount.label;"
  314.                 accesskey="¬ifier.prefs.ui.multiaccount.accesskey;"
  315.                 oncommand="updateManageAccountsButton()"/>
  316.       <button id="prefs.ui.multiaccount.accounts.button" label="Accounts"
  317.               oncommand="manageAccounts();"/>
  318.     </hbox>
  319.   </groupbox>
  320.  
  321.   <groupbox>
  322.     <caption label="¬ifier.prefs.groupbox.notifications;"/>
  323.     <checkbox id="prefs.ui.notification.enabled"
  324.               label="¬ifier.prefs.notification.enable.label;"
  325.               accesskey="¬ifier.prefs.notification.enable.accesskey;"
  326.               oncommand="updateNotificationButton()"/>
  327.  
  328.     <hbox align="center" class="indent">
  329.       <checkbox id="prefs.ui.notification.repeat"
  330.                 label="¬ifier.prefs.notification.repeat.label;"
  331.                 accesskey="¬ifier.prefs.notification.repeat.accesskey;"/>
  332.     </hbox>
  333.  
  334.     <checkbox id="prefs.ui.soundnotification.enabled"
  335.               label="¬ifier.prefs.soundnotification.play.label;"
  336.               accesskey="¬ifier.prefs.soundnotification.play.accesskey;"
  337.               oncommand="toogleSoundNotification()"/>
  338.     <hbox align="center" class="indent">
  339.       <textbox id="prefs.ui.soundnotification.textbox" onkeyup="updatePreviewButton()" flex="1"/>
  340.       <button id="prefs.ui.soundnotification.select"
  341.               label="¬ifier.prefs.soundnotification.select;"
  342.               oncommand="selectSound()"/>
  343.       <button id="prefs.ui.soundnotification.preview"
  344.               label="¬ifier.prefs.soundnotification.preview;"
  345.               oncommand="previewSound()"/>
  346.     </hbox>
  347.   </groupbox>
  348.  
  349.   <groupbox>
  350.     <caption label="¬ifier.prefs.groupbox.connection;"/>
  351.     <hbox align="center">
  352.       <label value="¬ifier.prefs.newmail.check.label-1;"
  353.              accesskey="¬ifier.prefs.newmail.check.label-1.accesskey;"
  354.              control="prefs.update.interval"/>
  355.       <textbox id="prefs.update.interval" style="width:3em;" maxlength="4" value=""/>
  356.       <label value="¬ifier.prefs.newmail.check.label-2;" />
  357.     </hbox>
  358.  
  359.     <checkbox id="prefs.autologin.enabled" label="¬ifier.prefs.autologin;"
  360.               accesskey="¬ifier.prefs.autologin.accesskey;"/>
  361.  
  362.     <checkbox id="prefs.use.unsecure.connection" label="¬ifier.prefs.use.unsecure.connection.label;"
  363.               accesskey="¬ifier.prefs.use.unsecure.connection.accesskey;"/>
  364.   </groupbox>
  365. </dialog>